package cn.wolfcode.car;

import cn.wolfcode.car.interceptor.LoginInterceptor;
import cn.wolfcode.car.interceptor.PermissionsInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

@SpringBootApplication
@MapperScan(basePackages = "cn.wolfcode.car.mapper")
public class App implements WebMvcConfigurer {
    private final List<String> excludePathList = Arrays.asList("/empLogin", "/login.html", "/css/**", "/js/**", "/img/**", "/");

    @Autowired
    private LoginInterceptor loginInterceptor;
    @Autowired
    private PermissionsInterceptor permissionsInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludePathList);

        registry.addInterceptor(permissionsInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludePathList);
    }

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}
